
/*
 * Copyright 2002-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 *版权所有2002-2022原作者。
 *
 *根据Apache许可证2.0版（“许可证”）获得许可；
 *除非符合许可证，否则不得使用此文件。
 *您可以在以下地址获取许可证副本：
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 *除非适用法律要求或书面同意，软件
 *根据许可证分发的内容是按“原样”分发的，
 *无任何明示或暗示的保证或条件。
 *有关管理权限和
 *许可证下的限制。
 */

package org.springframework.beans.factory.config;

import java.lang.reflect.Constructor;

import org.springframework.beans.BeansException;
import org.springframework.lang.Nullable;

/**
 * Extension of the {@link InstantiationAwareBeanPostProcessor} interface,
 * adding a callback for predicting the eventual type of a processed bean.
 *
 * <p><b>NOTE:</b> This interface is a special purpose interface, mainly for
 * internal use within the framework. In general, application-provided
 * post-processors should simply implement the plain {@link BeanPostProcessor}
 * interface.
 *
 * @author Juergen Hoeller
 * @since 2.0.3
 */
/**
 *{@link InstantiationAwareBeanPostProcessor}接口的扩展，
 *添加一个回调，用于预测已处理bean的最终类型。
 *
 *<p><b>注意：</b>此接口是一个专用接口，主要用于
 *框架内的内部使用。通常，提供的应用程序
 *后处理器应该简单地实现简单的｛@link BeanPostProcessor｝
 *接口。
 *
 *@作者Juergen Hoeller
 *@自2.0.3起
 */
public interface SmartInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessor {

	/**
	 * Predict the type of the bean to be eventually returned from this
	 * processor's {@link #postProcessBeforeInstantiation} callback.
	 * <p>The default implementation returns {@code null}.
	 * Specific implementations should try to predict the bean type as
	 * far as known/cached already, without extra processing steps.
	 * @param beanClass the raw class of the bean
	 * @param beanName the name of the bean
	 * @return the type of the bean, or {@code null} if not predictable
	 * @throws org.springframework.beans.BeansException in case of errors
	 */
	/**
	 *预测最终将从中返回的bean的类型
	 *处理器的｛@link#postProcessBefore实例化｝回调。
	 *＜p＞默认实现返回｛@code null｝。
	 *特定实现应尝试将bean类型预测为
	 *而无需额外的处理步骤。
	 *@param beanClass bean的原始类
	 *@param beanName bean的名称
	 *@返回bean的类型，如果不可预测，则返回｛@code null｝
	 *出现错误时@throws org.springframework.beans.BeansException
	 */
	@Nullable
	default Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
		return null;
	}

	/**
	 * Determine the type of the bean to be eventually returned from this
	 * processor's {@link #postProcessBeforeInstantiation} callback.
	 * <p>The default implementation returns the given bean class as-is.
	 * Specific implementations should fully evaluate their processing steps
	 * in order to create/initialize a potential proxy class upfront.
	 * @param beanClass the raw class of the bean
	 * @param beanName the name of the bean
	 * @return the type of the bean (never {@code null})
	 * @throws org.springframework.beans.BeansException in case of errors
	 * @since 6.0
	 */
	/**
	 *确定最终要从中返回的bean的类型
	 *处理器的｛@link#postProcessBefore实例化｝回调。
	 *＜p＞默认实现按原样返回给定的bean类。
	 *具体实现应充分评估其处理步骤
	 *以便预先创建/初始化潜在的代理类。
	 *@param beanClass bean的原始类
	 *@param beanName bean的名称
	 *@return bean的类型（从不｛@code null｝）
	 *出现错误时@throws org.springframework.beans.BeansException
	 *@自6.0起
	 */
	default Class<?> determineBeanType(Class<?> beanClass, String beanName) throws BeansException {
		return beanClass;
	}

	/**
	 * Determine the candidate constructors to use for the given bean.
	 * <p>The default implementation returns {@code null}.
	 * @param beanClass the raw class of the bean (never {@code null})
	 * @param beanName the name of the bean
	 * @return the candidate constructors, or {@code null} if none specified
	 * @throws org.springframework.beans.BeansException in case of errors
	 */
	/**
	 *确定要用于给定bean的候选构造函数。
	 *＜p＞默认实现返回｛@code null｝。
	 *@param beanClass bean的原始类（从不｛@code null｝）
	 *@param beanName bean的名称
	 *@返回候选构造函数，如果未指定，则返回｛@code null｝
	 *出现错误时@throws org.springframework.beans.BeansException
	 */
	@Nullable
	default Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName)
			throws BeansException {

		return null;
	}

	/**
	 * Obtain a reference for early access to the specified bean,
	 * typically for the purpose of resolving a circular reference.
	 * <p>This callback gives post-processors a chance to expose a wrapper
	 * early - that is, before the target bean instance is fully initialized.
	 * The exposed object should be equivalent to the what
	 * {@link #postProcessBeforeInitialization} / {@link #postProcessAfterInitialization}
	 * would expose otherwise. Note that the object returned by this method will
	 * be used as bean reference unless the post-processor returns a different
	 * wrapper from said post-process callbacks. In other words: Those post-process
	 * callbacks may either eventually expose the same reference or alternatively
	 * return the raw bean instance from those subsequent callbacks (if the wrapper
	 * for the affected bean has been built for a call to this method already,
	 * it will be exposes as final bean reference by default).
	 * <p>The default implementation returns the given {@code bean} as-is.
	 * @param bean the raw bean instance
	 * @param beanName the name of the bean
	 * @return the object to expose as bean reference
	 * (typically with the passed-in bean instance as default)
	 * @throws org.springframework.beans.BeansException in case of errors
	 */
	/**
	 *获取对指定bean的早期访问的引用，
	 *通常用于解析循环引用。
	 *＜p＞此回调使后处理器有机会公开包装器
	 *早期-即，在目标bean实例完全初始化之前。
	 *暴露的对象应与
	 *｛@link#postProcessBeforeInitialization｝/｛@link#postProcessAfterInitialization｝
	 *否则会暴露。注意，此方法返回的对象将
	 *除非后处理器返回不同的
	 *来自所述后处理回调的包装器。换句话说：那些后期处理
	 *回调可能最终暴露相同的引用，或者
	 *从这些后续回调中返回原始bean实例（如果包装器
	 *因为已经为调用该方法构建了受影响的bean，
	 *默认情况下，它将作为最终bean引用公开）。
	 *＜p＞默认实现按原样返回给定的｛@code bean｝。
	 *@param bean原始bean实例
	 *@param beanName bean的名称
	 *@返回要公开为bean引用的对象
	 *（通常将传入的bean实例作为默认值）
	 *出现错误时@throws org.springframework.beans.BeansException
	 */
	default Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
		return bean;
	}

}
